<?php

/*
 * Created on 01/03/2009
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

class SeasonDao {

    /**
     * Function to create a new, blank, season in the database
     */
    function createSeason() {
        if (executeQuery("insert into seasons (season, short_name, prize) values ('New Season', 'New Season', '')")) {
            $rs = executeQuery("select max(season_id) from seasons where season like 'New Season'");
            $row = mysql_fetch_row($rs);
            return $row[0];
        }
        return false;
    }

    function loadSeasons() {
        $seasons = array ();
        $rs = executeQuery("select season_id from seasons order by season_id desc");
        while ($row = mysql_fetch_row($rs)) {
            array_push($seasons, new Season($row[0]));
        }

        return $seasons;
    }

    function loadActiveSeasons() {
        $seasons = array ();
        $rs = executeQuery("select season_id from seasons where inactive=0 order by season_id desc");
        while ($row = mysql_fetch_row($rs)) {
            array_push($seasons, new Season($row[0]));
        }

        return $seasons;
    }

    function findWonSeasons($teamId) {
        $seasons = array ();
        $rs = executeQuery("select season_id from seasons where winner=$teamId order by season_id desc");
        while ($row = mysql_fetch_row($rs)) {
            array_push($seasons, new Season($row[0]));
        }
        return $seasons;
    }

}
?>
